<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="/static/layui/css/layui.css">
</head>
<body>
<fieldset class="layui-elem-field" >
    <legend>修改促销条件信息</legend>
    <div class="layui-field-box" >
        <form class="layui-form">
        <#--买赠编号 隐藏 传递的时候是空值，在后台用账号生成器自动生成-->
            <input type="hidden" name="conNo" value="${param.con_no!''}">

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">条件名称</label>
                    <div class="layui-input-inline">
                        <input type="text" name="conName" value="${param.con_name!''}" placeholder="请输入条件名称" lay-verify="require"  autocomplete="off" class="layui-input" >
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">优惠类型</label>
                <div class="layui-input-inline">
                    <select id="conType" name="conType" lay-verify="required">
                        <option value="">请选择</option>
                        <option value="满减">满减</option>
                        <option value="满赠">满赠</option>
                        <option value="立减">立减</option>
                        <option value="折扣">折扣</option>
                        <option value="返现">返现</option>
                        <option value="积分">积分</option>
                        <option value="包邮">包邮</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">销售渠道类型</label>
                    <div class="layui-input-inline">
                    <#-- onclick="province()"-->
                        <select id="spSlType" class="spSlType" lay-filter="spSlType" name="spSlType">
                            <option value="">请选择</option>
                            <option value="进线">热线</option>
                            <option value="网络">网络</option>
                        </select>
                    </div>
                </div>
            </div>

        <#--遍历查询供应商表-->
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">供应商</label>
                    <div class="layui-input-inline">
                        <select id="supId" name="supId">
                            <option value="">请选择供应商</option>
                        <#if list ? exists>
                            <#list list as item>
                                <option value="${item.id!''}">${item.supName!''}</option>
                            </#list>
                        <#else >
                        </#if>
                        </select>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">使用环节</label>
                    <div class="layui-input-inline">
                        <select id="segment" name="segment">
                            <option value="">请选择</option>
                            <option value="下单后">下单后</option>
                            <option value="支付">支付</option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">使用会员等级</label>
                    <div class="layui-input-inline">
                        <select id="conVipLevel" name="conVipLevel">
                            <option value="">请选择</option>
                            <option value="1">一级</option>
                            <option value="2">二级</option>
                            <option value="3">三级</option>
                            <option value="4">四级</option>
                            <option value="5">五级</option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">限定条件</label>
                    <div class="layui-input-inline">
                        <input type="text" name="conValue" value="${param.con_value!''}" lay-verify="require" placeholder="如：500" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">是否可与其他促销条件共存</label>
                    <div class="layui-input-inline">
                        <select id="isOtherConCombine" name="isOtherConCombine">
                            <option value="">请选择</option>
                            <option value="y">是</option>
                            <option value="n">否</option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">是否使用</label>
                    <div class="layui-input-inline">
                        <select id="isUsed" name="isUsed">
                            <option value="">请选择</option>
                            <option value="y">使用</option>
                            <option value="n">禁用</option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="addSaleCdn">确认</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</fieldset>
<script type="text/javascript" src="/static/layui/layui.js"></script>

<script>
    //Demo
    // 待学生自主完成
    layui.use(['form','layer','jquery'], function(){
        var form = layui.form();
        var layer = layui.layer;
        var $ = layui.jquery;

        //监听添加提交按钮
        form.on('submit(addSaleCdn)', function(params){
            var data = $("form").serializeArray();
            $.ajax({
                type: "POST",
                url: "/saleCdn/updataSaleCdnInfo",  //后台程序地址
                data: data,  //需要post的数据
                success: function(data){           //后台程序返回的标签，比如我喜欢使用1和0 表示成功或者失败
                    if (data.result == 'success'){   //如果成功了, 则关闭当前layer
                        layer.msg('添加成功',{
                            icon: 1,
                            time: 1000 //1秒关闭（如果不配置，默认是3秒）
                        },function(){//
                            //do something
                            //注册成功后，自动关闭当前注册页面
                            //先得到当前iframe层的索引
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                            //parent.layer.closeAll("iframe");
                        });
                    }
                }
            });
            return false;//return false 表示不通过页面刷新方式提交表单
        });

        //带回页面的select参数进行动态赋值
        var sp_sl_type = "${param.sp_sl_type!''}";
        var sup_id = "${param.sup_id!''}";
        var con_type = "${param.con_type!''}";
        var segment = "${param.segment!''}";
        var con_vip_level = "${param.con_vip_level!''}";
        var is_other_con_combine = "${param.is_other_con_combine!''}";
        var is_used = "${param.is_used!''}"
        $("#conType").find("option[value ='" + con_type + "']").attr("selected", "selected");
        $("#spSlType").find("option[value ='" + sp_sl_type + "']").attr("selected", "selected");
        $("#supId").find("option[value ='" + sup_id + "']").attr("selected", "selected");
        $("#segment").find("option[value ='" + segment + "']").attr("selected", "selected");
        $("#conVipLevel").find("option[value ='" + con_vip_level + "']").attr("selected", "selected");
        $("#isOtherConCombine").find("option[value ='" + is_other_con_combine + "']").attr("selected", "selected");
        $("#isUsed").find("option[value ='" + is_used + "']").attr("selected", "selected");

        // 重新渲染页面
        form.render();


    });
</script>
</body>
</html>